'use strict';

const Controller = require('egg').Controller;

class PatientController extends Controller {

  async remove() {
    const [ id ] = await ctx.service.patient.removePatient({
      userId: ctx.getUserId(),
      patientId: body.patientId,
    });

    ctx.body = {
      success: true,
      id,
    }
  }

  async create() {
    const { ctx } = this;
    const body = ctx.request.body;

    const [ id ] = await ctx.service.patient.newPatient({
      userId: ctx.getUserId(),
      image: body.image,
      name: body.name,
      idCardType: body.idCardType,
      idCardNum: body.idCardNum,
      sex: body.sex,
      birthday: body.birthday,
      address: body.address,
      addressHold: body.addressHold,
    });

    ctx.body = {
      success: true,
      id,
    }
  }

  async getPatientDetail() {
    const { ctx } = this;

    const [ patientDetail ] = await ctx.service.patient.getPatientDetail({
      patientId: ctx.getQuery('patientId'),
    })

    ctx.body = {
      success: true,
      patientDetail,
    };
  }

  async getPatientList() {
    const { ctx } = this;
    
    const listQuery = {};
    const [ option ] = ctx.getPageListOption();

    const [ list, totalCount ] = await ctx.service.patient.getPatientList(listQuery, option);

    ctx.apiPageList(list, totalCount);
  }
}

module.exports = PatientController;